import java.io.BufferedInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.net.InetAddress;
import java.net.Socket;

/**
 * Created by Анастасия on 09.06.2014.
 */
public class Client {

    public static void main(String[] arg) throws Exception {
        int serverPort = 4454;
        String address = "127.0.0.1";
        InetAddress ip_address = InetAddress.getByName(address);
        Socket socket = new Socket(ip_address, serverPort);
        System.out.println("Got server");

        File my_file = new File("C:\\Users\\Анастасия\\Desktop\\HeyJava.txt");
        byte[] fileBytes = new byte[(int) my_file.length()];
        FileInputStream fis = new FileInputStream(my_file);
        BufferedInputStream buf = new BufferedInputStream(fis);
        DataOutputStream z = new DataOutputStream(socket.getOutputStream());

        int n = 0;
        int count = 0;
        System.out.println(my_file.length());
        z.writeLong(my_file.length());
        while ((count != -1) && (n != fileBytes.length)) {
            count = buf.read(fileBytes, n, fileBytes.length);
            z.write(count);
            z.write(fileBytes, 0, fileBytes.length);
            n = n + count;
            //System.out.println();
        }

        /*while (count != -1) {
            count = z.write(fileBytes);
            z.write(fileBytes, 0, fileBytes.length);
            n = n + count;
        }*/

        z.flush();
        z.close();
        socket.close();
    }
}

